var app = angular.module("app", ['ngRoute', 'myTemplates']);

app.config(['$routeProvider', function($routeProvider) {
	$routeProvider
		.when("/", {
			templateUrl: "templates/app.html",
			controller: "AppCtrl",
			controllerAs: "app"
		})
		.when('/param/:message1/:message2', {
			templateUrl: 'templates/param.html',
			controller: 'ParamCtrl',
			controllerAs: 'param'
		})
		.when('/redirectTo', {
			redirectTo: '/'
		})
		.when('/resolveRoute', {
			templateUrl: "templates/app.html",
			controller: 'ResolveCtrl',
			resolve: {
				// I will cause a 1 second delay
				delay: ['$q', '$timeout', function($q, $timeout) {
					var delay = $q.defer();
					$timeout(delay.resolve, 4000);
					return delay.promise;
				}]
			}
		})
		.otherwise({
			template: "<h1>404 Not Found</h1>",
		});
}]);

app.controller('AppCtrl', ['$scope', function($scope) {
	//var self = this;
	// this.message = 'The app routing is working!';
	$scope.message = 'The app routing is working!';
}]);

app.controller('ParamCtrl', ['$scope', '$routeParams', function($scope, $routeParams) {
	//var self = this;
	// this.message = 'The app routing is working!';
	$scope.message = $routeParams.message1 + ' ' + $routeParams.message2;
}]);

app.controller('ResolveCtrl', ['$scope', function($scope) {
	$scope.message = "I'm a resolve!";
}]);

app.controller('LocationCtrl', ['$scope', '$location', function($scope, $location) {
	$scope.changeLocation = function() {
		console.log($location.path());
		$location.path('/');
	};
}]);


